﻿{extend name="public:base" /}

{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">名称</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="name" placeholder="请输入名称" value="{$info.name}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">封面图</label>
                                <div class="col-sm-6">
                                    <input type="file" id="img_file" accept="image/*" style="display: none">
                                    <input type="hidden" class="hidden_value" name="img" id="img" value="{$info['img']|default=''}"/>
                                    <div class="btn btn-w-m btn-primary" onclick="uploadImage('img_file', 'img', 'form-uploaded-box-single', false, 1)">原图上传</div>
                                    <div class="btn btn-w-m btn-primary" onclick="openCrop('form-uploaded-box-single', 1)">裁剪上传</div>

                                    <div class="form-uploaded-box" id="form-uploaded-box-single" style="width: 140px">
                                        {if $info.img}
                                        <div class="form-uploaded-img-box">
                                            <img class="form-uploaded-box-img" src="{:getPicture($info.img)}" data-id="{$info.img}">
                                            <i class="form-uploaded-img-preview iconfont icon-yulan" onclick="previewImg(this, 'form-uploaded-img-preview')"></i>
                                            <i class="form-uploaded-img-del iconfont icon-close" onclick="delImage(this, 'cropper_uploaded_img_ids', 'cropper_uploaded_img_paths', 'form-')"></i>
                                        </div>
                                        {/if}
                                    </div>
                                </div>

                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">描述</label>
                                <div class="col-sm-3">
                                    <textarea class="form-control" name="des" rows="8">{$info.des}</textarea>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">价格</label>
                                <div class="col-sm-3">
                                    <input type="number" class="form-control" name="price" placeholder="请输入价格" value="{$info.price}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">分佣比例</label>
                                <div class="col-sm-3">
                                    <input type="number" class="form-control" name="rate" placeholder="请输入分佣比例" value="{$info.rate}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-lg-1 col-form-label">记账服务</label>
                                <div class="col-lg-3">
                                    <input type="radio" name="is_record" lay-filter="is_record" value="1" title="是" {$info.is_record !== 0 ? 'checked' : ''}>
                                    <input type="radio" name="is_record" lay-filter="is_record" value="0" title="否" {$info.is_record=== 0 ? 'checked' : ''}>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item days">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">服务周期</label>
                                <div class="col-sm-3">
                                    <input type="number" class="form-control" name="days" placeholder="请输入服务周期" value="{$info.days}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-lg-1 col-form-label">推荐</label>
                                <div class="col-lg-3">
                                    <input type="radio" name="is_recommend" value="1" title="推荐" {$info.is_recommend !=0 ? 'checked' : ''}>
                                    <input type="radio" name="is_recommend" value="0" title="不推荐" {$info.is_recommend== 0 ? 'checked' : ''}>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-lg-1 col-form-label">状态</label>
                                <div class="col-lg-3">
                                    <input type="radio" name="is_upper" value="1" title="上架" {$info.is_upper !=0 ? 'checked' : ''}>
                                    <input type="radio" name="is_upper" value="0" title="下架" {$info.is_upper== 0 ? 'checked' : ''}>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="row">
                                <label class="col-sm-1 col-form-label">服务须知</label>
                                <div class="col-lg-3">
                                    <div class="ibox ">
                                        <textarea id="editor_id" name="know">{$info.know}</textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="row">
                                <label class="col-sm-1 col-form-label">服务简介</label>
                                <div class="col-lg-6">
                                    <div class="ibox ">
                                        <textarea id="editor_id2" name="content">{$info.content}</textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                        </div>

                        <input type="hidden" name="id" value="{:input('id')}">

                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post2">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/cropper-img-mask" cropper_uploaded_img_ids="cropper_uploaded_img_ids" cropper_uploaded_img_paths="cropper_uploaded_img_paths" crop_preview_box="crop-preview-box" /}{include file="public/preview-img-mask" swiper-id="cropper-preview" /}

{/block}

{block name='js'}
<script src="__STATIC__/layui/layui.js"></script>
<script type="text/javascript" src="__PLUG__/kindeditor/kindeditor-all.js"></script>
<script>
    <!-- 实例化编辑器 -->
    var editor, editor2
    initKindEditor2('editor_id');
    initKindEditor3('editor_id2');

    function initKindEditor2(editor_id, width = 710, height = 500, items = ['source', 'undo', 'redo', '|', 'preview', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'link', 'unlink', '|', 'fullscreen']) {
        KindEditor.ready(function (K) {
            editor = K.create('#' + editor_id, {
                width: width,
                height: height,
                items: items
            });
        });
    }

    function initKindEditor3(editor_id, width = 710, height = 500, items = ['source', 'undo', 'redo', '|', 'preview', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'clearhtml', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'link', 'unlink', '|', 'fullscreen']) {
        KindEditor.ready(function (K) {
            editor2 = K.create('#' + editor_id, {
                width: width,
                height: height,
                items: items
            });
        });
    }

    $(function () {
        var is_record = '{$info.is_record}' ? '{$info.is_record}' : 0
        if (is_record == 1) {
            $('.days').show();
        } else {
            $('.days').hide();
        }
    })
    layui.use('form', function () {
        var form = layui.form;
        form.on('radio(is_record)', function (data) {
            if (data.value == 1) {
                $('.days').show();
            } else {
                $('.days').hide();
            }
        });
    });


    // 表单提交
    $('.ajax-post2').click(function () {
        //加载层
        var index = layer.load(2, {shade: [0.2, '#000']});

        var action = $(this).parents().attr("action");
        if (!action) {
            var url = window.location.href;
        } else {
            //取出第一个字符
            var first = action.slice(0, 1);
            if (first == '/') {
                var url = action;
            } else {
                var url = '/' + action
            }
        }

        editor.sync();
        editor2.sync();

        var formData = $('form').serialize();
        $.post(url, formData, function (res) {
            if (res.result == 1) {
                setTimeout(function () {
                    window.location.href = res.url;
                }, res.timer)
            } else if (res.result == 2) {
                layer.close(index);
                layer.msg(res.msg);
            } else if (res.result == 3) {
                layer.close(index);
                layer.msg(res.msg);
                //后台登录失败，需要刷新【表单令牌】和【验证码】
                if (res.token) $("[name='__token__']").val(res.token);
                $('#captcha').attr('src', "/captcha.html?" + Math.random())
            }
        }, 'json');

        setTimeout(function () {
            layer.close(index);
        }, 3000)
        return false;
    });
</script>{/block}
